package com.beikbank.controller;

import com.alibaba.fastjson.JSONObject;
import com.beikbank.bean.qo.UserListQO;
import com.beikbank.bean.qo.UserLoginQO;
import com.beikbank.bean.result.ResponseResult;
import com.beikbank.bean.vo.OnlineListVO;
import com.beikbank.bean.vo.UserListVO;
import com.beikbank.bean.vo.UserLoginVO;
import com.beikbank.service.BKUserService;
import com.beikbank.util.baseAction.BaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by wangzhanjin on 2018/1/16.
 */
@Controller
@RequestMapping("/user")
public class UserController extends BaseAction{
    @Autowired
    private BKUserService bkUserService;


    @RequestMapping("/user_list.do")
    public String getUserList(){
        return "user/user_list.html";
    }
    @RequestMapping("/acc_list.do")
    public String getAccList(){
        return "user/acc_list.html";
    }
    @RequestMapping("/login_log.do")
    public String getUserLoginLog(){
        return "user/login_log.html";
    }
    @RequestMapping("/online_list.do")
    public String getOnlineList(){
        return "user/online_list.html";
    }


    /*—————————————————————————————————————————————————————*/

    /**
     * 用户查询
     * @return
     */
    @RequestMapping("/list/search.do")
    @ResponseBody
//    @RequiresPermissions("bk:user:search")//后端权限控制
    public List<UserListVO> getUserListSearch(){
        UserListQO userListQO = JSONObject.parseObject(jsonObj.toString(), UserListQO.class);
        List<UserListVO> userListVOlist = bkUserService.userListSearch(userListQO);
//        Map<String,Object> maps=new JSONObject();
//        maps.put("userListVOlist",userListVOlist);
        return userListVOlist;
    }

    /**
     * 用户锁定
     * @return
     */
    @RequestMapping("/lock.do")
    @ResponseBody
    public ResponseResult updateUserLock(){
        String userCode = processDataNull(hashMap.get("userCode"));
        Integer integer = bkUserService.updateUserLock(userCode);
        return responseResult.OK(integer+"");
    }

    /**
     * 日志查询
     * @return
     */
    @RequestMapping("/log/search.do")
    @ResponseBody
    public List<UserLoginVO> getUserLogSearch(){
        UserLoginQO userLoginQO = JSONObject.parseObject(jsonObj.toString(), UserLoginQO.class);
        List<UserLoginVO> list = bkUserService.userLogSearch(userLoginQO);
        return list;
    }


    /**
     * 用户在线统计
     * @return
     */
    @RequestMapping("/online/search.do")
    @ResponseBody
    public OnlineListVO getOnlineSearch(){
        String dateType = processDataNull(hashMap.get("dateType"));
        String timeEnd = processDataNull(hashMap.get("timeEnd"));
        OnlineListVO onlineListVO = bkUserService.getOnlineSearch(dateType,timeEnd);
        return onlineListVO;
    }

}
